@extends('default.layouts.adminPublic')
@section('title', '编辑员工')
<link rel="stylesheet" href="{{asset('/default/css/admin/drop-down.css')}}">
<link rel="stylesheet" href="{{asset('/vendor/jedate/skin/jedate.css')}}">
@section('content')

        <!--导航开始-->
<div class="crumb_warp">
    <i class="fa fa-home"></i> <a href="{{url('admin')}}">首页</a> &raquo; 客服员工管理
</div>
<!--导航结束-->

<!--结果集标题与导航组件 开始-->
<div class="result_wrap">
    <div class="result_title">
        <h3>修改员工</h3>
    </div>
    <div class="result_content">
        <div class="short_wrap">
            <a href="{{url('admin/workerhandle/create')}}"><i class="fa fa-plus"></i>添加员工</a>
            <a href="{{url('admin/workerhandle')}}"><i class="fa fa-recycle"></i>员工列表</a>
        </div>
    </div>
</div>
<!--结果集标题与导航组件 结束-->

<div class="result_wrap">
    <form action="{{ url("admin/workerhandle/".$userInfo->uid) }}" name="userform" method="post">
        <input type="hidden" name="_method" value="put">
        {{ csrf_field() }}
        <input type="hidden" name="handleRole" value="1">
        <table class="add_tab">
            <tbody>
            {{--<tr>--}}
                {{--<th width="120">头像：</th>--}}
                {{--<td>--}}
                    {{--<div class="img">--}}
                    {{--<span class="upimg">--}}
                        {{--<!--用来存放item-->--}}
                        {{--<div id="fileList"></div>--}}
                        {{--<div id="filePicker" ><img id="userImg" src="{{ $userInfo->img!='' ? url($userInfo->img) : url("default/images/admin/upimg.png") }}"></div>--}}
                    {{--</span>--}}
                        {{--<input type="hidden" id="imgUrl" name="img" value="{{ $userInfo->img }}">--}}
                        {{--<p></p>--}}
                    {{--</div>--}}
                {{--</td>--}}
            {{--</tr>--}}
            <tr>
                <th><i class="require">*</i> 账号：</th>
                <td>
                    <input type="text" value="{{ $userInfo->name }}" name="name" placeholder="请输入账号名称" readonly><span>{!! $errors->has('name') ? "<em>*".$errors->first('name')."</em>" : '<em>*</em>账号' !!}</span>
                </td>
            </tr>
            <tr>
                <th><i class="require">*</i> 员工名字：</th>
                <td>
                    <input type="text" value="{{ $userInfo->worker_name }}" name="worker_name" placeholder="请输入员工名字"><span>{!! $errors->has('worker_name') ? "<em>*".$errors->first('worker_name')."</em>" : '<em>*</em>员工姓名' !!}</span>
                </td>
            </tr>
            <tr>
                <th><i class="require">*</i> 密码：</th>
                <td>
                    <input type="password" value="" name="password" placeholder="员工密码"><span>{!! $errors->has('password') ? "<em>*".$errors->first('password')."</em>" : '<em>*</em>不修改密码，请留空' !!}</span>
                </td>
            </tr>
            <tr>
                <th style="vertical-align: top;"><i class="require"></i> 添加角色：</th>
                <td>
                    @if(count($RoleUser) > 0 && count($Role) > 0)
                        @foreach($RoleUser as $k => $v)
                            <div class="list roleSelect" id="roleSelect{{ $k }}">
                                <select id="role{{ $k }}" name="role[{{ $k }}]" class="ui-select">
                                    <option value="0">添加角色</option>
                                    @foreach($Role as $RoleValue)
                                        @if($RoleValue->id == $v->role_id)
                                            <option value="{{ $RoleValue->id }}" selected>{{ $RoleValue->display_name }}</option>
                                        @else
                                            <option value="{{ $RoleValue->id }}">{{ $RoleValue->display_name }}</option>
                                        @endif
                                    @endforeach
                                </select>
                                @if(count($RoleUser) == ($k+1))
                                    <span class="floatLeft"><a class="toAddRole" onclick="addRoleClick({{ $k.','.($k-1) }})">增加角色</a></span>
                                @else
                                    <span class="floatLeft"><a class="toDelRole" onclick="destroyRoleClick({{ $k }})">取消该角色</a></span>
                                @endif
                            </div>
                        @endforeach
                    @else
                        <div class="list roleSelect" id="roleSelect0">
                            <select id="role0" name="role[0]" class="ui-select">
                                <option value="0">添加角色</option>
                                @if(count($Role) > 0)
                                    @foreach($Role as $RoleValue)
                                        <option value="{{ $RoleValue->id }}">{{ $RoleValue->display_name }}</option>
                                    @endforeach
                                @endif
                            </select>
                            <span class="floatLeft"><a class="toAddRole" onclick="addRoleClick(0,0)">增加角色</a></span>
                        </div>
                    @endif

                </td>
            </tr>

            <tr>
                <th style="vertical-align: top;"><i class="require"></i> 上班时间角色：</th>
                <td>
                    <div class="list roleSelect" id="roleSelect0" >
                        <select name="work_role_id" class="ui-select" style="margin-top: 8px;">
                            <option value="0">添加角色</option>
                            @if(count($CrmWorkRole) > 0)
                                @foreach($CrmWorkRole as $v)
                                    @if($userInfo->work_role_id == $v->id)
                                        <option value="{{ $v->id }}" selected>{{ $v->name }}</option>
                                    @else
                                        <option value="{{ $v->id }}">{{ $v->name }}</option>
                                    @endif
                                @endforeach
                            @endif
                        </select>
                    </div>
                </td>
            </tr>

            <tr>
                <th><i class="require">*</i> 性别：</th>
                <td>
                    @if( $userInfo->sex != '' )
                        男<input type="radio" name="sex" value="1" {{ $userInfo->sex==1 ? "checked" : '' }}>女<input type="radio"  name="sex" value="2"  {{ $userInfo->sex==2 ? "checked" : '' }}>
                    @else
                        男<input type="radio" name="sex" value="1" checked>女<input type="radio"  name="sex" value="2">
                    @endif
                </td>
            </tr>
            <tr>
                <th><i class="require"></i> 出生日期：</th>
                <td>
                    <input class='datainp wicon timeput' id='inpstart' name='birthday' type='text' placeholder='出生日期' value='{{ substr($userInfo->birthday,0,10)=='0000-00-00' ? "1949-10-01":substr($userInfo->birthday,0,10) }}' readonly>
                    <span>请选择出生日期</span>
                </td>
            </tr>
            <tr>
                <th><i class="require"></i> 座机号：</th>
                <td>
                    <input type="text" value="{{ $userInfo->phone }}" name="phone" placeholder="请输入座机号"><span>Exp：0576-83365888-1</span>
                </td>
            </tr>
            <tr>
                <th><i class="require"></i> 手机号码：</th>
                <td>
                    <input type="text" value="{{ $userInfo->mobile == 0 ? '' : $userInfo->mobile }}" name="mobile" placeholder="请输入手机联系号码"><span>{!! $errors->has('mobile') ? '<em>'.$errors->first('mobile').'</em>' : 'Exp:13188886666' !!}</span>
                </td>
            </tr>
            <tr>
                <th><i class="require"></i> 微信号：</th>
                <td>
                    <input type="text" value="{{ $userInfo->weichat }}" name="weichat" placeholder="微信号"><span>Exp：weichat_123</span>
                </td>
            </tr>
            <tr>
                <th><i class="require"></i> QQ：</th>
                <td>
                    <input type="text" value="{{ $userInfo->qq == 0 ? '' : $userInfo->qq }}" name="qq" placeholder="QQ"><span>{!! $errors->has('qq') ? '<em>'.$errors->first('qq').'</em>' : 'Exp：QQ号' !!}</span>
                </td>
            </tr>
            <tr>
                <th><i class="require"></i> email：</th>
                <td>
                    <input id="email" type="email"  name="email" value="{{ $userInfo->email }}" placeholder="Email"> <span>{{ $errors->first('email')  }}Exp：15hr@qq.com</span>
                </td>
            </tr>
            <tr>
                <th><i class="require"></i> 个人宣言：</th>
                <td>
                    <textarea placeholder="个人宣言" name="enounce">{{ $userInfo->enounce }}</textarea><span>* 最多200字</span>
                </td>
            </tr>

            <tr>
                <th></th>
                <td>
                    <input type="submit" value="提交">
                    <input type="button" class="back" onclick="history.go(-1)" value="返回">
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</div>
<script type="text/javascript" src="{{asset('/default/js/jquery.js')}}"></script>
<script type="text/javascript" src="{{asset('/default/js/jquery/jquery.form.js')}}"></script>
<script type="text/javascript" src="{{ asset("/default/js/jquery/jquery-ui.min.js") }}"></script>
<script type="text/javascript" src="{{ asset("/default/js/jquery/select-widget-min.js") }}"></script>
<script type="text/javascript" src="{{ asset("/default/js/jquery/jquery.jedate.js") }}"></script>
{{--<script type="text/javascript" src="{{asset('/vendor/webuploader/dist/webuploader.min.js')}}"></script>--}}
<script type="text/javascript" src="{{asset('/vendor/org/layer/layer.js')}}"></script>
<script>
    //初始化时间
    var start = {
        format: 'YYYY-MM-DD',
        minDate: "1949-10-01", //设定最小日期为当前日期$.nowDate(0)
        festival:false,
        //isinitVal:true,
        maxDate: '2099-06-16', //最大日期
    };
    $("#inpstart").jeDate(start);

    //角色增加与删除
    function addRoleClick(id,i){
        i = id;
        //把增加换成删除
        current = $("#roleSelect"+(id));
        current.find("span").eq(0).find(".toAddRole").attr("class",'toDelRole');
        current.find("span").eq(0).find(".toDelRole").attr("onclick",'destroyRoleClick('+id+')');
        current.find("span").eq(0).find(".toDelRole").html('&nbsp;取消该角色<input type="hidden" value="'+i+'">');
        id ++;
        toAddselectHtml(id,i);//载入select
    }
    function destroyRoleClick(id){
        $("#roleSelect"+id).remove();
    }
    function toAddselectHtml(id,i){
        addHtml = "";
        addHtml += '<div class="select-main">';
        addHtml += '<div class="select-arrow"></div>';//reverse
        addHtml += '<div class="select-set">添加角色<input name="role['+id+']" type="hidden" value="0"></div>';
        addHtml += '<div class="select-block" id="selectblock'+id+'" style="display: none;">';
        addHtml += '<ul class="select-list">';
        addHtml += '<li class="select-items">添加角色<input type="hidden" value="0"></li>';
        @if(count($Role) > 0)
            @foreach($Role as $RoleValue)
                addHtml += '<li class="select-items">{{ $RoleValue->display_name }}<input type="hidden" value="{{ $RoleValue->id }}"></li>';
        @endforeach
    @endif
    addHtml += '</ul>';
        addHtml += '</div>';
        addHtml += '</div>';

        addHtml += '<span class="floatLeft">';

        addHtml += '<a class="toAddRole" onclick="addRoleClick('+id+','+i+')">&nbsp;增加角色<input type="hidden" value="'+id+'"></a>';

        addHtml += '</span>';

        $("<div></div>",{
            //class:'list roleSelect',
            id:'roleSelect'+id,
            html:addHtml
        }).insertAfter("#roleSelect"+i);
        $("#roleSelect"+id).attr("class","list roleSelect");

        $("#roleSelect"+id).find(".select-set").click(function(){
            //隐藏所有select
            //$(".select-arrow").attr("class","select-arrow");//去掉蓝色小箭头
            $(".select-block").animate({
                height:'hide'
            },1);
            //当前selectid
            roleSelect = "#roleSelect"+id;
            //显示当前select
            $("#selectblock"+id).animate({
                height:'show'
            },1);
            // $(roleSelect).find(".select-arrow").attr("class","select-arrow reverse");//蓝色小箭头
            $("#selectblock"+id).find("li").each(function(){
                $(this).click(function(){
                    //选中
                    $("#selectblock"+id).find("li").attr("class","select-items");
                    $(this).attr("class","select-items active");
                    $(roleSelect).find(".select-set").html($(this).html());
                    roleId = $(roleSelect).find(".select-set").find("input").val();
                    $(roleSelect).find(".select-set").find("input").attr("name","role["+id+"]");
                    //隐藏
                    //$(roleSelect).find(".select-arrow").attr("class","select-arrow");//去掉蓝色小箭头
                    $("#selectblock"+id).animate({
                        height:'hide'
                    },1);
                });
            });
            //点击事件隐藏select
            $(".main").click(function(event){
                if($(event.target).closest(".select-set").length == 0){
                    //$(roleSelect).find(".select-arrow").attr("class","select-arrow");//去掉蓝色小箭头
                    $("#selectblock"+id).animate({
                        height:'hide'
                    },1);
                }else{
                    //本身不操作
                }
            });
        });
    }
</script>
<script type="text/javascript">
    {{--var BASE_URL='{{url('/')}}/';--}}
    {{--uploadAvatar("#filePicker");--}}
    {{--//上传头像--}}
    {{--function uploadAvatar(upavatar) {--}}
        {{--var uploaderavatar = WebUploader.create({--}}
            {{--auto: true,--}}
            {{--formData: {--}}
                {{--_token: "{{csrf_token()}}"--}}
            {{--},--}}
            {{--duplicate: true,--}}
            {{--// swf文件路径--}}
            {{--swf: BASE_URL + 'public/vendor/webuploader/dist/Uploader.swf',--}}
            {{--// 文件接收服务端。--}}
            {{--server: "{{ route("imgUpload") }}",--}}
            {{--// 选择文件的按钮。可选。--}}
            {{--// 内部根据当前运行是创建，可能是input元素，也可能是flash.--}}
            {{--pick : "#filePicker",--}}
            {{--compress: {--}}
                {{--width: 200,--}}
                {{--height: 200,--}}
                {{--// 图片质量，只有type为`image/jpeg`的时候才有效。--}}
                {{--//quality: 100,--}}
                {{--// 是否允许放大，如果想要生成小图的时候不失真，此选项应该设置为false.--}}
                {{--allowMagnify: true,--}}
                {{--// 是否允许裁剪。--}}
                {{--crop: true,--}}
                {{--compressSize: 0,--}}
                {{--noCompressIfLarger: false--}}
            {{--},--}}
            {{--accept: {--}}
                {{--title: 'Images',--}}
                {{--extensions: 'gif,jpg,jpeg,bmp,png',--}}
                {{--mimeTypes: '.gif,.jpg,.jpeg,.bmp,.png'--}}
            {{--},--}}
            {{--// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！--}}
            {{--fileSingleSizeLimit: 2000 * 1024--}}
        {{--});--}}
        {{--//上传文件出错时--}}
        {{--uploaderavatar.on('error', function(file){--}}
            {{--if(file == 'F_EXCEED_SIZE'){--}}
                {{--layer.msg('文件大小不能超过2M！',{time:1200});--}}
            {{--}--}}
            {{--if(file == 'F_DUPLICATE'){--}}
                {{--layer.msg('此文件已经存在队列当中，不能重复上传！',{time:1200});--}}
            {{--}--}}
            {{--if(file == 'Q_EXCEED_NUM_LIMIT'){--}}
                {{--layer.msg('你已经上传了文件！',{time:1200});--}}
            {{--}--}}
            {{--if(file == 'Q_TYPE_DENIED'){--}}
                {{--layer.msg('文件类型不匹配，请重新上传！',{time:1200});--}}
            {{--}--}}
        {{--});--}}
        {{--uploaderavatar.on('uploadSuccess', function (file, response) {--}}
            {{--if (response.status == 200) {--}}
                {{--$("#userImg").attr("src", response.url);--}}
                {{--$("#imgUrl").val(response.saveUrl);--}}
            {{--} else {--}}
                {{--layer.msg(response.info);--}}
            {{--}--}}
        {{--});--}}
    {{--}--}}

    Tip ={!! !empty(session("ok")) ? session("ok") : "''" !!};
    if(Tip.status != undefined){
        switch (Tip.status){
            case 0:
                layer.msg(Tip.msg, {icon: 6});
                break;
            case 1:
                layer.msg(Tip.msg, {icon: 5});
                break;
        }
    }
</script>
@endsection
